import time

from selenium import webdriver

from ..exception.TestException import TestException
from ..common.ui.Selector import Selector
import pytest

from .ICheck import ICheck


def test_select():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/icheck/index.html")
    time.sleep(2)
    try:
        icheck = ICheck(browser, "input[name='fruit1']", Selector.CSS_SELECTOR)
        time.sleep(1)
        icheck.setValue("Banana")
    finally:
        browser.close()

def test_select_not_exist_value():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/icheck/index.html")
    time.sleep(2)
    try:
        icheck = ICheck(browser, "input[name='fruit1']", Selector.CSS_SELECTOR)
        time.sleep(1)
        with pytest.raises(TestException):
            icheck.setValue("BananaXXXXXXXX")
    finally:
        browser.close()

if __name__ == '__main__':
    pytest.main(['-s','ICheck_test.py'])